package io.renren.modules.ssp.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.ssp.entity.SspOfferEntity;
import io.renren.modules.ssp.service.SspOfferService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 上游数据表
 *
 * @author haijun.zhang
 * @email haijun917@qq.com
 * @date 2018-08-11 17:51:03
 */
@RestController
@RequestMapping("ssp/sspoffer")
public class SspOfferController {
    @Autowired
    private SspOfferService sspOfferService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ssp:sspoffer:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sspOfferService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("ssp:sspoffer:info")
    public R info(@PathVariable("id") Integer id){
        SspOfferEntity sspOffer = sspOfferService.selectById(id);

        return R.ok().put("sspOffer", sspOffer);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ssp:sspoffer:save")
    public R save(@RequestBody SspOfferEntity sspOffer){
        sspOfferService.insert(sspOffer);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ssp:sspoffer:update")
    public R update(@RequestBody SspOfferEntity sspOffer){
        ValidatorUtils.validateEntity(sspOffer);
        sspOfferService.updateAllColumnById(sspOffer);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ssp:sspoffer:delete")
    public R delete(@RequestBody Integer[] ids){
        sspOfferService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
